package basic;

import javax.vecmath.Matrix3d;

import src.Quaternion;

public class CrtBody {
	private String id = "";
	private Transform position = null;
	private BoxTree boundingtree = null;

	public CrtBody(String id, BoxTree hierc) {
		this.id = id;
		this.boundingtree=hierc;
		position = new Transform(null);
	}
	public String getID() {
		return id;
	}
	public Transform getPosition() {
		return position;
	}

	public void setPosition(DoubleXYZ pos)
	{
		this.position.setPosition(pos);
	}

	public void setOrientation(Quaternion q)
	{
		this.position.setOrientation(q);
	}

	public BoxTree getBoundingTree() {
		return this.boundingtree;
	}

	/**
	 * Il metodo verifica l'intersezione tra 
	 * due gerarchie di tipo AABB
	 * @param b
	 * @param t
	 * @return
	 */
	public static boolean intersect(CrtBody a,CrtBody b)
	{
		Transform t= new Transform(new DoubleXYZ(0,0,0));
		t.setInvMult(a.position, b.position);
		Matrix3d m=t.absolute();
		return BoxTree.intersect(a.getBoundingTree(),b.getBoundingTree(),t,m);
	}

	public String toString() {
		String doc = "<CrtRigidBody " + id + " " + ">";
		return doc;
	}}
